import {Component, OnInit} from '@angular/core';
import {Title} from '@angular/platform-browser';
import {NgForm} from '@angular/forms';
import {ReCaptchaV3Service} from 'ng-recaptcha';
import {AuthService} from '../auth.service';

@Component({
  selector: 'app-signin',
  templateUrl: './signin.component.html',
  styleUrls: ['./signin.component.scss']
})
export class SigninComponent implements OnInit {
  constructor(
    private titleService: Title,
    private reCaptchaV3Service: ReCaptchaV3Service,
    private authService: AuthService
  ) {
  }

  ngOnInit() {
    this.titleService.setTitle(
      'ورود'
    );
  }

  login(loginForm: NgForm) {
    const mobileNumber = Number(loginForm.value.mobileNumber);
    const password = loginForm.value.password;
    this.reCaptchaV3Service.execute('login')
      .subscribe(captchaResponse => this.authService.login(mobileNumber, password, captchaResponse));
  }
}
